﻿using System;
using System.Web;

namespace MikeKappel.Com.CS
{
    public static partial class Helper
    {
        /// <summary>
        /// Gets the domain section for the Host Name
        /// www.(domain.com)
        /// </summary>
        /// <returns>Last 2 segments of the domain host</returns>
        public static String Domain()
        {
            return Domain(HttpContext.Current.Request.Url.Host);
        }
        /// <summary>
        /// Gets the domain section for the Host Name
        /// www.(domain.com)
        /// </summary>
        /// <returns>Last 2 segments of the domain host</returns>
        public static String Domain(String host)
        {
            String domain = host;
            if (domain.Contains("."))
            {
                String[] hostSegments = domain.Split('.');
                Array.Reverse(hostSegments);
                domain = hostSegments[1] + "." + hostSegments[0];
            }
            return domain;
        }
    }
}
